﻿using System;
using System.Collections.ObjectModel;
using TestRunner.App.Base;
using TestRunner.App.Entities;
using TestRunner.App.Model;
using SD.Libs.Navigation.Contracts;
using GalaSoft.MvvmLight.Command;
using TestRunner.App.Common;

namespace TestRunner.App.ViewModels
{
    public class CustomerListVM : MyVMBase
    {
        #region Fields

        IModel _model;
        private INavigationService _navigationService;

        #endregion Fields

        #region Commands

        private RelayCommand<int> _navigateToDetailCommand;
        public RelayCommand<int> NavigateToDetailCommand
        {
            get
            {
                if (_navigateToDetailCommand == null)
                {
                    _navigateToDetailCommand = new RelayCommand<int>(
                        idParam =>
                        {
                            string url = NavigationHelper.CustomerURL(idParam);
                            _navigationService.NavigateTo(new Uri(url, UriKind.Relative));
                        }
                        );
                }
                return _navigateToDetailCommand;
            }
        }


        #endregion Commands

        #region Properties for bindings

        private ObservableCollection<Customer> _customers;
        public ObservableCollection<Customer> Customers
        {
            get
            {
                return _customers;
            }

            set
            {
                _customers = value;
                RaisePropertyChanged("Customers");
            }
        }

        #endregion Properties for bindings

        #region Constructor

        public CustomerListVM(INavigationService navigationService, IModel model)
        {
            _model = model;

            _navigationService = navigationService;
            Customers = _model.GetAllCustomers();
        }

        #endregion Constructor
    }
}
